package AlexDB.Command;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;


@CommandTypeAttribute("string")
public class StringCommand extends BaseCommand<HashMap<String,Object>>
{
    // ICommandOperationEvent event;
    public StringCommand()
    {
        super();
        if(map == null) 
        {
            map = new HashMap<String,Object>();
            putToDataMap();
        }

    }

    public Object commandExecute(Object[] args) throws Exception {
        var command = args[1].toString();
        // var key = args[2].toString();

        Method thisMethods = getInvokeMethod(command);
        var toMethodsArgs =  Arrays.asList(args).subList(2, args.length);
        return thisMethods.invoke(this,toMethodsArgs.toArray());
    }

   @CommandOperationAttribute("set")
    Object Put(String key,Object value)
    {
        map.put(key, value);
        return value;
    }
    
    @CommandOperationAttribute("get")
    Object Get(String key)
    {
        // if(event!=null)event.invoke();
        return map.get(key);
    }

    @CommandOperationAttribute("rm")
    Object Remove(String key)
    {
        // if(event!=null)event.invoke();
        return map.remove(key);
    }
}
